/**
 * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package com.mad.bikepony.model;

import com.liferay.portal.kernel.bean.AutoEscapeBeanHandler;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.util.StringBundler;
import com.liferay.portal.model.BaseModel;
import com.liferay.portal.model.impl.BaseModelImpl;

import com.mad.bikepony.service.AgentLocalServiceUtil;

import java.io.Serializable;

import java.lang.reflect.Proxy;

import java.util.HashMap;
import java.util.Map;

/**
 * @author nicola
 */
public class AgentClp extends BaseModelImpl<Agent> implements Agent {
	public AgentClp() {
	}

	public Class<?> getModelClass() {
		return Agent.class;
	}

	public String getModelClassName() {
		return Agent.class.getName();
	}

	public long getPrimaryKey() {
		return _agentId;
	}

	public void setPrimaryKey(long primaryKey) {
		setAgentId(primaryKey);
	}

	public Serializable getPrimaryKeyObj() {
		return new Long(_agentId);
	}

	public void setPrimaryKeyObj(Serializable primaryKeyObj) {
		setPrimaryKey(((Long)primaryKeyObj).longValue());
	}

	@Override
	public Map<String, Object> getModelAttributes() {
		Map<String, Object> attributes = new HashMap<String, Object>();

		attributes.put("agentId", getAgentId());
		attributes.put("password", getPassword());
		attributes.put("name", getName());
		attributes.put("surname", getSurname());
		attributes.put("mobilePhone", getMobilePhone());
		attributes.put("status", getStatus());
		attributes.put("lastPos_latitude", getLastPos_latitude());
		attributes.put("lastPos_longitude", getLastPos_longitude());
		attributes.put("lastUpdate", getLastUpdate());

		return attributes;
	}

	@Override
	public void setModelAttributes(Map<String, Object> attributes) {
		Long agentId = (Long)attributes.get("agentId");

		if (agentId != null) {
			setAgentId(agentId);
		}

		String password = (String)attributes.get("password");

		if (password != null) {
			setPassword(password);
		}

		String name = (String)attributes.get("name");

		if (name != null) {
			setName(name);
		}

		String surname = (String)attributes.get("surname");

		if (surname != null) {
			setSurname(surname);
		}

		String mobilePhone = (String)attributes.get("mobilePhone");

		if (mobilePhone != null) {
			setMobilePhone(mobilePhone);
		}

		Integer status = (Integer)attributes.get("status");

		if (status != null) {
			setStatus(status);
		}

		Double lastPos_latitude = (Double)attributes.get("lastPos_latitude");

		if (lastPos_latitude != null) {
			setLastPos_latitude(lastPos_latitude);
		}

		Double lastPos_longitude = (Double)attributes.get("lastPos_longitude");

		if (lastPos_longitude != null) {
			setLastPos_longitude(lastPos_longitude);
		}

		Long lastUpdate = (Long)attributes.get("lastUpdate");

		if (lastUpdate != null) {
			setLastUpdate(lastUpdate);
		}
	}

	public long getAgentId() {
		return _agentId;
	}

	public void setAgentId(long agentId) {
		_agentId = agentId;
	}

	public String getPassword() {
		return _password;
	}

	public void setPassword(String password) {
		_password = password;
	}

	public String getName() {
		return _name;
	}

	public void setName(String name) {
		_name = name;
	}

	public String getSurname() {
		return _surname;
	}

	public void setSurname(String surname) {
		_surname = surname;
	}

	public String getMobilePhone() {
		return _mobilePhone;
	}

	public void setMobilePhone(String mobilePhone) {
		_mobilePhone = mobilePhone;
	}

	public int getStatus() {
		return _status;
	}

	public void setStatus(int status) {
		_status = status;
	}

	public double getLastPos_latitude() {
		return _lastPos_latitude;
	}

	public void setLastPos_latitude(double lastPos_latitude) {
		_lastPos_latitude = lastPos_latitude;
	}

	public double getLastPos_longitude() {
		return _lastPos_longitude;
	}

	public void setLastPos_longitude(double lastPos_longitude) {
		_lastPos_longitude = lastPos_longitude;
	}

	public long getLastUpdate() {
		return _lastUpdate;
	}

	public void setLastUpdate(long lastUpdate) {
		_lastUpdate = lastUpdate;
	}

	public BaseModel<?> getAgentRemoteModel() {
		return _agentRemoteModel;
	}

	public void setAgentRemoteModel(BaseModel<?> agentRemoteModel) {
		_agentRemoteModel = agentRemoteModel;
	}

	public void persist() throws SystemException {
		if (this.isNew()) {
			AgentLocalServiceUtil.addAgent(this);
		}
		else {
			AgentLocalServiceUtil.updateAgent(this);
		}
	}

	@Override
	public Agent toEscapedModel() {
		return (Agent)Proxy.newProxyInstance(Agent.class.getClassLoader(),
			new Class[] { Agent.class }, new AutoEscapeBeanHandler(this));
	}

	@Override
	public Object clone() {
		AgentClp clone = new AgentClp();

		clone.setAgentId(getAgentId());
		clone.setPassword(getPassword());
		clone.setName(getName());
		clone.setSurname(getSurname());
		clone.setMobilePhone(getMobilePhone());
		clone.setStatus(getStatus());
		clone.setLastPos_latitude(getLastPos_latitude());
		clone.setLastPos_longitude(getLastPos_longitude());
		clone.setLastUpdate(getLastUpdate());

		return clone;
	}

	public int compareTo(Agent agent) {
		long primaryKey = agent.getPrimaryKey();

		if (getPrimaryKey() < primaryKey) {
			return -1;
		}
		else if (getPrimaryKey() > primaryKey) {
			return 1;
		}
		else {
			return 0;
		}
	}

	@Override
	public boolean equals(Object obj) {
		if (obj == null) {
			return false;
		}

		AgentClp agent = null;

		try {
			agent = (AgentClp)obj;
		}
		catch (ClassCastException cce) {
			return false;
		}

		long primaryKey = agent.getPrimaryKey();

		if (getPrimaryKey() == primaryKey) {
			return true;
		}
		else {
			return false;
		}
	}

	@Override
	public int hashCode() {
		return (int)getPrimaryKey();
	}

	@Override
	public String toString() {
		StringBundler sb = new StringBundler(19);

		sb.append("{agentId=");
		sb.append(getAgentId());
		sb.append(", password=");
		sb.append(getPassword());
		sb.append(", name=");
		sb.append(getName());
		sb.append(", surname=");
		sb.append(getSurname());
		sb.append(", mobilePhone=");
		sb.append(getMobilePhone());
		sb.append(", status=");
		sb.append(getStatus());
		sb.append(", lastPos_latitude=");
		sb.append(getLastPos_latitude());
		sb.append(", lastPos_longitude=");
		sb.append(getLastPos_longitude());
		sb.append(", lastUpdate=");
		sb.append(getLastUpdate());
		sb.append("}");

		return sb.toString();
	}

	public String toXmlString() {
		StringBundler sb = new StringBundler(31);

		sb.append("<model><model-name>");
		sb.append("com.mad.bikepony.model.Agent");
		sb.append("</model-name>");

		sb.append(
			"<column><column-name>agentId</column-name><column-value><![CDATA[");
		sb.append(getAgentId());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>password</column-name><column-value><![CDATA[");
		sb.append(getPassword());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>name</column-name><column-value><![CDATA[");
		sb.append(getName());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>surname</column-name><column-value><![CDATA[");
		sb.append(getSurname());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>mobilePhone</column-name><column-value><![CDATA[");
		sb.append(getMobilePhone());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>status</column-name><column-value><![CDATA[");
		sb.append(getStatus());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>lastPos_latitude</column-name><column-value><![CDATA[");
		sb.append(getLastPos_latitude());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>lastPos_longitude</column-name><column-value><![CDATA[");
		sb.append(getLastPos_longitude());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>lastUpdate</column-name><column-value><![CDATA[");
		sb.append(getLastUpdate());
		sb.append("]]></column-value></column>");

		sb.append("</model>");

		return sb.toString();
	}

	private long _agentId;
	private String _password;
	private String _name;
	private String _surname;
	private String _mobilePhone;
	private int _status;
	private double _lastPos_latitude;
	private double _lastPos_longitude;
	private long _lastUpdate;
	private BaseModel<?> _agentRemoteModel;
}